export default {
  namespaced: true,
  state: () => ({
    data: [
    ]
  }),
  mutations: {
    // 添加地址
    add_address (state, item) {
      if (item.isDefault) {
        state.data.map(el => (el.isDefault = !item.isDefault))
      }
      item = { ...item, id: Date.now(), address: item.province + item.city + item.county + item.addressDetail }
      state.data.unshift(item)
    },
    // 删除地址
    del_address (state, id) {
      state.data.splice(id, 1)
    },
    // 更新地址
    update_address (state, { id, item }) {
      item = { ...item, address: item.province + item.city + item.county + item.addressDetail}
      state.data[id] = item
    }
  }
}
